package come;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class Window extends JFrame implements ActionListener{
	private static final long serialVersionUID = 1L;
	JTextArea jt;
	JTextField tf;
	JButton jb;
	Receiver rc;
	public Window() {
		setVisible(true);
		setBounds(1200, 100, 500, 400);
		setTitle("对话框");
		setLayout(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		jt = new JTextArea();
		JScrollPane jp = new JScrollPane(jt);
		jp.setBounds(30, 20, 400, 200);
		tf = new JTextField();
		tf.setBounds(30, 250, 300, 50);
		jb = new JButton("发送");
		jb.setBounds(330, 250, 100, 50);
		jb.addActionListener(this);
		//jp.add(jb);
		//jp.add(tf);
		//jp.add(jt);
		add(jp);
		add(tf);
		add(jb);
		rc=new Receiver(jt);
		SocketUtil.setReceiver(rc);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				new Window();
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand() == "发送") {
			SimpleDateFormat time = new SimpleDateFormat("YYYY年MM月dd日hh:mm:ss:sss");
			String s = time.format(new Date());
			jt.append(s + "\n" + tf.getText());
			SocketUtil.sendMessage(tf.getText());						
		}
	}

}
